<!--包房管理 -->
<template>
  <div class="admin-body">
    <el-row>
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>包房管理</el-breadcrumb-item>
        <div v-if="this.$store.state.login.user.type == 1" style="text-align: right" >
          <span style="color: red">请选择KTV</span>
          <el-select v-model="$store.state.login.shopID" clearable  @change="SelectShop()" placeholder="请选择KTV查询">
            <el-option
              v-for="item in $store.state.login.shopData"
              :key="item.shop_id"
              :label="item.name"
              :value="item.shop_id">
            </el-option>
          </el-select>
        </div>
      </el-breadcrumb>
    </el-row>
    <el-row style="padding: 15px">

      <el-row class="main">
        <el-row  style="min-height: 40px;display: flex;">

        </el-row>
        <!--表格-->
        <el-table
          select-on-indeterminate
          ref="multipleTable"
          border
          align="left"
          :data="tableData">
          <el-table-column
            type="index"
            label="序号"
            width="50">
          </el-table-column>
          <el-table-column
            label="包房类型">
            <template slot-scope="scope">
             {{pdlx(scope.row[0].type)}}
            </template>
          </el-table-column>

          <el-table-column
            prop="session_type"
            label="场次">
            <template slot-scope="scope">
              <div v-for="item in scope.row" style="display: flex;">
                <span style="float: left;">{{pdlx1(item.session_type)}}({{item.number}})</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="操作">
            <template slot-scope="scope">
              <el-button @click="edit(scope.row)"  style="" size="small" type="text">
                修改
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <el-row style="margin-top: 20px">
          <el-col :xs="24" :sm="24" :md="24" :lg="24" align="right">
            <el-pagination
              style="text-align: right;margin-bottom:70px;"
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="page"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="dataTotal">
            </el-pagination>
          </el-col>
        </el-row>
      </el-row>
    </el-row>
    <el-dialog title="编辑" :visible.sync="editVisible" width="500px" :append-to-body="true" :modal-append-to-body="false">
      <el-form v-for="(item,index) in editdata" :key="index">
        <el-form-item :label="pdlx1(item.session_type)"  :label-width="formLabelWidth" prop="number">
          <el-input v-model="item.number" clearable>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="SubmitEdit('editdata')">确定</el-button>
        <el-button @click="editVisible = false">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
  import MyOneUpload from '../../components/MyOneUpload'
  export default {
    name: "PrivateRoom",
    components:{
      MyOneUpload
    },
    activated() {
      if (!this.$store.state.login.in) {
        this.$router.push({name: "login", params: {userId: 123}})
      }
      if (this.$store.state.login.user.type == 1) {
        this.shop_id = this.$store.state.login.shopID
      }else {
        this.shop_id = this.$store.state.login.user.id
      }
      this.getstart()
    },
    data() {
      return {
        pageSize: 10,
        page: 1,
        dataTotal: 0,
        tableData:[],
        addVisible:false,
        formLabelWidth:'130px',
        adddata:{
          shop_id:'',
          type:'',
          number:'',
          room_name:'',
          session_type	:[],
          room_size	:'',
          // rule	:'无',
          begin_time	:'',
          over_time	:'',
        },
        addrules:{
          type: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          number: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          room_name: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          session_type: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          room_size: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          // rule: [
          //   {required: true, message: '请输入', trigger: 'blur'}
          // ],
          begin_time: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          over_time: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
        },
        options: [
          {
            value: 1,
            label: '中小包'
          },
          {
            value: 2,
            label: '大包'
          },
          {
            value: 3,
            label: '豪包'
          },
        ],
        type:'',
        editVisible:false,
        editdata:[
          {
            shop_id:'',
            type:'',
            number:'',
            session_type	:'',
          },
          {
            shop_id:'',
            type:'',
            number:'',
            session_type	:'',
          },
          {
            shop_id:'',
            type:'',
            number:'',
            session_type	:'',
          },
        ],

        editrules:{
          type: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          number: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          session_type: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
        },
        key:'',
        shop_id:'',
      }
    },
    methods: {
      SelectShop(){
        this.shop_id = this.$store.state.login.shopID
        this.getstart()
      },
      pdlx(type){
        let dateArr = ['小包','中小包','大包','豪包',];
        return dateArr[type]
      },
      pdlx1(type){
        let dateArr = ['上午场','下午场','黄金场','午夜场',];
        return dateArr[type]
      },
      edit(data){
        console.log(data)
        this.editdata = JSON.parse(JSON.stringify(data))
        for (var i=0;i<3;i++) {
          this.editdata[i].shop_id = this.shop_id
        }
        this.editVisible = true
      },
      restPassword(id){
        this.restVisible = true
        this.restdata.platform_id = id
      },
      SubmitEdit(formName) {
        let thi = this
        var a = {json: JSON.stringify(thi.editdata)}
        thi.mySubmit('editRoom', a).then(function (code) {
          if (code == 200) {
            thi.editVisible = false
            thi.getstart()
          }
        })
      },
      details(data){
        // this.$store.state.login.platformId = data
        if (data == 1){
          this.$router.push({name:'privateRoomDetail'})
        } else if (data == 2) {
          this.$router.push({name:'shoppingMallDetail'})
        }else {
          this.$router.push({name:'comment'})
        }


      },
      add(){
        this.addVisible = true
      },
      //绑定表格数据，分页
      getstart() {
        let thi = this
        const prams = {
          page:thi.page,
          pageSize:thi.pageSize,
          shop_id: thi.shop_id,
          key:thi.key,
        }
        thi.mySelectAll('roomList',prams).then(function (value) {
          thi.tableData = value.data
          console.log(thi.tableData)
          thi.dataTotal = value.Total
        })
      },

      //选择展示数量
      handleSizeChange(val) {
        this.pageSize = val
        this.getstart()
      },
      //分页
      handleCurrentChange(val) {
        this.page = val
        this.getstart()
      },
      //状态改变提示
      changeMes(id, state) {
        var heeh = '该'
        var caozuo = '禁用'
        if (id.length > 1) {
          heeh = '这些'
        }
        if (state == 0) {
          caozuo = '删除'
        }
        let thi = this
        thi.$confirm('此操作将'+caozuo + heeh+'包房', '是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        }).then(() => {
          thi.submitState(id,state)
        }).catch(() => {
          thi.$message({
            type: 'info',
            message: '已取消'
          });
        });
      },
      //删除
      submitState(id,state) {
        let thi = this
        const por = {
          shop_id: thi.shop_id,
          id: id,
          state: state,
        }
        console.log(por)
        thi.mySubmit('editRoomState', por).then(function (code) {
          if (code == 200) {
            thi.getstart()
          }
        })
      },
    }
  }

</script>

<style scoped>
  .main {
    background-color: white;
    min-height: 500px;
    padding: 10px;
    border: #EDEDED 1px solid;
    border-radius: 5px;
  }
  .el-row{
    /*防止页面抖动*/
    width: calc(100% - 2px) !important;
  }
  .cmap{
    width: 100%;
    height: 400px;
    margin-bottom: 10px;
  }
  .search-cont{
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 999999;
  }
  .mapTxt {
    text-align: center;
    width: 220px;
    padding: 4px;
    overflow: hidden;
    font-size: 14px;
    font-weight: bold;
    white-space: normal;
    margin-left: 40px;
    margin-top: 40px;
  }
</style>
